<template>
  <view class="write">
    <view class="payment">
      <!-- 主体信息选项 -->
      <view class="title">
        <text>主体信息</text>
        <tip
          content="请填写商家的营业执照/登记证书、经营者/法人的证件等信息"
        ></tip>
      </view>
      <view class="subject_info">
        <!-- 营业执照信息 -->
        <template
          v-if="
            subject_info.subject_type == 'SUBJECT_TYPE_INDIVIDUAL' ||
            subject_info.subject_type == 'SUBJECT_TYPE_ENTERPRISE'
          "
        >
          <view class="optionItem">
            <view class="optionTitle">
              <text>营业执照照片</text>
              <tip
                content="请上传彩色照片or彩色扫描件or加盖公章鲜章的复印件、可添加“微信支付”相关水印（如微信支付认证）"
              ></tip>
            </view>
            <view
              class="addPic"
              @click="addPic('license_copy')"
              v-if="subject_info.business_license_info.license_copy == ''"
            >
              <text class="iconfont icon-camera"></text>
              <text>上传图片</text>
            </view>
            <view class="addPic" @click="addPic('license_copy')" v-else>
              <image
                :src="subject_info.business_license_info.license_copy"
              ></image>
            </view>
          </view>
          <template v-if="showBusiness">
            <view class="optionItem">
              <text class="optionTitle">注册号</text>
              <input
                type="text"
                placeholder="请输入注册号"
                :disabled="status == 2"
                v-model="subject_info.business_license_info.license_number"
              />
            </view>
            <view class="optionItem">
              <text class="optionTitle">商户名称</text>
              <input
                type="text"
                placeholder="请输入商户名称"
                :disabled="status == 2"
                v-model="subject_info.business_license_info.merchant_name"
              />
            </view>
            <view class="optionItem">
              <view class="optionTitle">
                <text>经营者姓名</text>
                <tip
                  content="若营业执照上商户名称为空或为“无”，请填写“个体户+经营者名字”，如“个体户张三”"
                ></tip>
              </view>
              <input
                type="text"
                placeholder="请输入经营者姓名"
                :disabled="status == 2"
                v-model="subject_info.business_license_info.legal_person"
              />
            </view>
          </template>
          <showMore v-model="showBusiness"></showMore>
        </template>
        <!-- 登记证书信息 -->
        <template
          v-if="
            subject_info.subject_type == 'SUBJECT_TYPE_INSTITUTIONS' ||
            subject_info.subject_type == 'SUBJECT_TYPE_OTHERS'
          "
        >
          <view class="optionItem">
            <view class="optionTitle">
              <text>登记证书照片</text>
              <tip
                content="请上传彩色照片or彩色扫描件or加盖公章鲜章的复印件、可添加“微信支付”相关水印（如微信支付认证）"
              ></tip>
            </view>
            <view
              class="addPic"
              @click="addPic('cert_copy')"
              v-if="subject_info.certificate_info.cert_copy == ''"
            >
              <text class="iconfont icon-camera"></text>
              <text>上传图片</text>
            </view>
            <view class="addPic" @click="addPic('cert_copy')" v-else>
              <image :src="subject_info.certificate_info.cert_copy"></image>
            </view>
          </view>
          <view class="optionItem">
            <text class="optionTitle">登记证书类型</text>
            <myPicker
              :disabled="status == 2"
              v-model="subject_info.certificate_info.cert_type"
              placeholoder="请选择登记证书类型"
              :options="cert_type_list"
              rangeKey="name"
              rangeValue="value"
            ></myPicker>
          </view>
          <view class="optionItem">
            <text class="optionTitle">证书号</text>
            <input
              type="text"
              placeholder="请输入证书号"
              :disabled="status == 2"
              v-model="subject_info.certificate_info.cert_number"
            />
          </view>
          <view class="optionItem">
            <text class="optionTitle">商户名称</text>
            <input
              type="text"
              placeholder="请输入商户名称"
              :disabled="status == 2"
              v-model="subject_info.certificate_info.merchant_name"
            />
          </view>
          <view class="optionItem">
            <text class="optionTitle">注册地址</text>
            <input
              type="text"
              placeholder="请输入注册地址"
              :disabled="status == 2"
              v-model="subject_info.certificate_info.company_address"
            />
          </view>
          <view class="optionItem">
            <view class="optionTitle">
              <text>法人姓名</text>
              <tip content="请填写登记证书上的法定代表人姓名"></tip>
            </view>
            <input
              type="text"
              placeholder="请输入法人姓名"
              :disabled="status == 2"
              v-model="subject_info.certificate_info.legal_person"
            />
          </view>
          <view class="optionItem">
            <text class="optionTitle">证件是否长期</text>
            <view class="radioList">
              <u-radio-group
                v-model="subject_info.certificate_info.is_long"
                :disabled="status == 2"
              >
                <u-radio :name="0">短期</u-radio>
                <u-radio :name="1">长期</u-radio>
              </u-radio-group>
            </view>
          </view>
          <view class="optionItem">
            <text class="optionTitle">组织机构代码证有效期开始日期</text>
            <myPicker
              v-model="subject_info.certificate_info.period_begin"
              placeholoder="请选择有效期开始日期"
              :disabled="status == 2"
              mode="date"
            ></myPicker>
          </view>
          <view
            class="optionItem"
            v-if="subject_info.certificate_info.is_long == 0"
          >
            <text class="optionTitle">组织机构代码证有效期结束日期</text>
            <myPicker
              :disabled="status == 2"
              v-model="subject_info.certificate_info.period_end"
              placeholoder="请选择有效期结束日期"
              mode="date"
            ></myPicker>
          </view>
        </template>
        <!-- 组织机构代码证 -->
        <template
          v-if="
            subject_info.subject_type == 'SUBJECT_TYPE_ENTERPRISE' ||
            subject_info.subject_type == 'SUBJECT_TYPE_INSTITUTIONS' ||
            subject_info.subject_type == 'SUBJECT_TYPE_OTHERS'
          "
        >
          <view class="optionItem">
            <text class="optionTitle">营业执照是否三证合一</text>
            <view class="radioList">
              <u-radio-group
                :disabled="status == 2"
                v-model="subject_info.organization_info.is_composite"
              >
                <u-radio :name="0">否</u-radio>
                <u-radio :name="1">是</u-radio>
              </u-radio-group>
            </view>
          </view>
          <template v-if="subject_info.organization_info.is_composite == 0">
            <view class="optionItem">
              <text class="optionTitle">组织机构代码证照片</text>
              <view
                class="addPic"
                @click="addPic('organization_copy')"
                v-if="subject_info.organization_info.organization_copy == ''"
              >
                <text class="iconfont icon-camera"></text>
                <text>上传图片</text>
              </view>
              <view class="addPic" @click="addPic('organization_copy')" v-else>
                <image
                  :src="subject_info.organization_info.organization_copy"
                ></image>
              </view>
            </view>
            <view class="optionItem">
              <text class="optionTitle">组织机构代码</text>
              <input
                type="text"
                placeholder="请输入组织机构代码"
                :disabled="status == 2"
                v-model="subject_info.organization_info.organization_code"
              />
            </view>
            <view class="optionItem">
              <text class="optionTitle">证件是否长期</text>
              <view class="radioList">
                <u-radio-group
                  v-model="subject_info.organization_info.is_long"
                  :disabled="status == 2"
                >
                  <u-radio :name="0">短期</u-radio>
                  <u-radio :name="1">长期</u-radio>
                </u-radio-group>
              </view>
            </view>
            <view class="optionItem">
              <text class="optionTitle">开始日期</text>
              <myPicker
                :disabled="status == 2"
                v-model="subject_info.organization_info.org_period_begin"
                placeholoder="请选择有效期开始日期"
                mode="date"
              ></myPicker>
            </view>
            <view
              class="optionItem"
              v-if="subject_info.organization_info.is_long == 0"
            >
              <text class="optionTitle">结束日期</text>
              <myPicker
                :disabled="status == 2"
                v-model="subject_info.organization_info.org_period_end"
                placeholoder="请选择有效期结束日期"
                mode="date"
              ></myPicker>
            </view>
          </template>
        </template>
        <!-- 经营者/法人身份证件 -->
        <view class="optionItem">
          <text class="optionTitle">证件类型</text>
          <myPicker
            :disabled="status == 2"
            v-model="subject_info.identity_info.id_doc_type"
            placeholoder="请选择证书类型"
            :options="id_doc_list"
            rangeKey="name"
            rangeValue="value"
          ></myPicker>
        </view>
        <template
          v-if="
            subject_info.identity_info.id_doc_type ==
            'IDENTIFICATION_TYPE_IDCARD'
          "
        >
          <view class="optionItem">
            <text class="optionTitle">身份证人像面照片</text>
            <view
              class="addPic"
              @click="addPic('id_card_copy')"
              v-if="subject_info.identity_info.id_card_info.id_card_copy == ''"
            >
              <text class="iconfont icon-camera"></text>
              <text>上传图片</text>
            </view>
            <view class="addPic" @click="addPic('id_card_copy')" v-else>
              <image
                :src="subject_info.identity_info.id_card_info.id_card_copy"
              ></image>
            </view>
          </view>
          <view class="optionItem">
            <text class="optionTitle">身份证国徽面照片</text>
            <view
              class="addPic"
              @click="addPic('id_card_national')"
              v-if="
                subject_info.identity_info.id_card_info.id_card_national == ''
              "
            >
              <text class="iconfont icon-camera"></text>
              <text>上传图片</text>
            </view>
            <view class="addPic" @click="addPic('id_card_national')" v-else>
              <image
                :src="subject_info.identity_info.id_card_info.id_card_national"
              ></image>
            </view>
          </view>
          <template v-if="showCard">
            <view class="optionItem">
              <text class="optionTitle">身份证姓名</text>
              <input
                type="text"
                placeholder="请输入身份证姓名"
                :disabled="status == 2"
                v-model="subject_info.identity_info.id_card_info.id_card_name"
              />
            </view>
            <view class="optionItem">
              <text class="optionTitle">身份证号码</text>
              <input
                type="text"
                placeholder="请输入身份证号码"
                :disabled="status == 2"
                v-model="subject_info.identity_info.id_card_info.id_card_number"
              />
            </view>
            <view class="optionItem">
              <text class="optionTitle">证件是否长期</text>
              <view class="radioList">
                <u-radio-group
                  v-model="subject_info.identity_info.is_long"
                  :disabled="status == 2"
                >
                  <u-radio :name="0">短期</u-radio>
                  <u-radio :name="1">长期</u-radio>
                </u-radio-group>
              </view>
            </view>
            <view class="optionItem">
              <text class="optionTitle">身份证有效期开始日期</text>
              <myPicker
                :disabled="status == 2"
                v-model="
                  subject_info.identity_info.id_card_info.card_period_begin
                "
                placeholoder="请选择有效期开始日期"
                mode="date"
              ></myPicker>
            </view>
            <view
              class="optionItem"
              v-if="subject_info.identity_info.is_long == 0"
            >
              <text class="optionTitle">身份证有效期结束日期</text>
              <myPicker
                :disabled="status == 2"
                v-model="
                  subject_info.identity_info.id_card_info.card_period_end
                "
                placeholoder="请选择有效期结束日期"
                mode="date"
              ></myPicker>
            </view>
          </template>
          <showMore v-model="showCard"></showMore>
        </template>
        <template
          v-if="
            subject_info.identity_info.id_doc_type ==
              'IDENTIFICATION_TYPE_OVERSEA_PASSPORT' ||
            subject_info.identity_info.id_doc_type ==
              'IDENTIFICATION_TYPE_HONGKONG_PASSPORT' ||
            subject_info.identity_info.id_doc_type ==
              'IDENTIFICATION_TYPE_MACAO_PASSPORT' ||
            subject_info.identity_info.id_doc_type ==
              'IDENTIFICATION_TYPE_TAIWAN_PASSPORT'
          "
        >
          <view class="optionItem">
            <text class="optionTitle">证件照片</text>
            <view
              class="addPic"
              @click="addPic('id_doc_copy')"
              v-if="subject_info.identity_info.id_doc_info.id_doc_copy == ''"
            >
              <text class="iconfont icon-camera"></text>
              <text>上传图片</text>
            </view>
            <view class="addPic" @click="addPic('id_doc_copy')" v-else>
              <image
                :src="subject_info.identity_info.id_doc_info.id_doc_copy"
              ></image>
            </view>
          </view>
          <view class="optionItem">
            <text class="optionTitle">证件姓名</text>
            <input
              type="text"
              placeholder="请输入身份证姓名"
              :disabled="status == 2"
              v-model="subject_info.identity_info.id_doc_name"
            />
          </view>
          <view class="optionItem">
            <text class="optionTitle">证件号码</text>
            <input
              type="text"
              placeholder="请输入身份证号码"
              :disabled="status == 2"
              v-model="subject_info.identity_info.id_doc_info.id_doc_number"
            />
          </view>
          <view class="optionItem">
            <text class="optionTitle">证件是否长期</text>
            <view class="radioList">
              <u-radio-group
                v-model="subject_info.identity_info.is_long"
                :disabled="status == 2"
              >
                <u-radio :name="0">短期</u-radio>
                <u-radio :name="1">长期</u-radio>
              </u-radio-group>
            </view>
          </view>
          <view class="optionItem">
            <text class="optionTitle">身份证有效期开始日期</text>
            <myPicker
              v-model="subject_info.identity_info.id_doc_info.doc_period_begin"
              placeholoder="请选择有效期开始日期"
              mode="date"
              :disabled="status == 2"
            ></myPicker>
          </view>
          <view
            class="optionItem"
            v-if="subject_info.identity_info.is_long == 0"
          >
            <text class="optionTitle">身份证有效期结束日期</text>
            <myPicker
              v-model="subject_info.identity_info.id_doc_info.doc_period_end"
              placeholoder="请选择有效期结束日期"
              mode="date"
              :disabled="status == 2"
            ></myPicker>
          </view>
        </template>
      </view>
      <view class="title">
        <text>经营信息</text>
        <tip
          content="请填写商家的经营业务信息、售卖商品/提供服务场景信息。"
        ></tip>
      </view>
      <!-- 经营信息选项 -->
      <view class="business_info">
        <view class="optionItem">
          <view class="optionTitle">
            <text>商户简称</text>
            <tip
              type="2"
              :content="[
                '1、在支付完成页向买家展示、需与微信经营类目相关。',
                '1、简称要求：',
                '支持单纯以人名来命名，若为个体户经营、可用“个体户+经营者名称”或“经营者名称+业务”命名，如“个体户张三“或”张三餐饮店“',
                '不支持无实际意义的文案，如“xx特约商户”、“800”、“xx客服电话xx”'
              ]"
            ></tip>
          </view>
          <input
            type="text"
            placeholder="请输入商户简称"
            :disabled="status == 2"
            v-model="business_info.merchant_shortname"
          />
        </view>
        <view class="optionItem">
          <text class="optionTitle">客服电话</text>
          <input
            type="text"
            placeholder="请输入客服电话"
            :disabled="status == 2"
            v-model="business_info.service_phone"
          />
        </view>
      </view>
      <view class="title">
        <text>结算账户</text>
        <tip content="请填写商家提现收款的银行账户信息"></tip>
      </view>
      <!-- 结算账户选项 -->
      <view class="bank_account_info">
        <view class="optionItem">
          <text class="optionTitle">账户类型</text>
          <myPicker
            v-model="bank_account_info.bank_account_type"
            placeholoder="请选择账户"
            :options="bank_type_list"
            rangeKey="name"
            rangeValue="value"
            :disabled="status == 2"
          ></myPicker>
        </view>
        <view class="optionItem">
          <view class="optionTitle">
            <text>开户名称</text>
            <tip
              type="2"
              :content="[
                '1、选择“经营者个人银行卡”时，开户名称必须与“经营者证件姓名”一致。',
                '2、选择“对公银行账户”时，开户名称必须与营业执照/登记证书的“商户名称”一致。'
              ]"
            ></tip>
          </view>
          <input
            type="text"
            placeholder="请输入开户名称"
            :disabled="status == 2"
            v-model="bank_account_info.account_name"
          />
        </view>
        <view class="optionItem">
          <text class="optionTitle">开户银行</text>
          <myPicker
            v-model="bank_account_info.account_bank"
            placeholoder="请选择银行"
            :options="bank_list"
            :disabled="status == 2"
          ></myPicker>
        </view>
        <view class="optionItem">
          <text class="optionTitle">开户银行省市</text>
          <picker
            v-model="bank_account_info.code_list"
            mode="region"
            @change="changeArea"
            :disabled="status == 2"
          >
            <view class="chooseType">
              <text>{{
                bank_account_info.code_list.length
                  ? bank_account_info.address_list.join(",")
                  : "请选择开户行所在地区"
              }}</text>
              <text class="iconfont icon-arrow-right"></text>
            </view>
          </picker>
        </view>
        <view class="optionItem">
          <text class="optionTitle">银行账号</text>
          <input
            type="text"
            placeholder="请输入银行账号"
            :disabled="status == 2"
            v-model="bank_account_info.account_number"
          />
        </view>
      </view>
      <view class="title">
        <text>超级管理员</text>
        <tip
          content="请填写商家的超级管理员信息，超级管理员需在开户后进行签约，并接受日常重要信息和进行资金操作，请确定其为商户法定代表人或负责人"
        ></tip>
      </view>
      <!-- 超级管理员选项 -->
      <view class="contact_info">
        <view class="optionItem">
          <text class="optionTitle">超管姓名</text>
          <input
            type="text"
            placeholder="请输入超管姓名"
            :disabled="status == 2"
            v-model="contact_info.contact_name"
          />
        </view>
        <view class="optionItem">
          <view class="optionTitle">
            <text>超管证件号码</text>
            <tip
              content="请填写超级管理员的证件号码，可传身份证，来往内地通行证，来往大陆通行证，护照等证件号码"
            ></tip>
          </view>
          <input
            type="text"
            placeholder="请输入证件号码"
            :disabled="status == 2"
            v-model="contact_info.contact_id_number"
          />
        </view>
        <view class="optionItem">
          <view class="optionTitle">
            <text>手机号码</text>
            <tip
              content="用于接收微信支付的重要管理信息及日常验证码，超管签约时自助修改手机号，并进行短信验证"
            ></tip>
          </view>
          <input
            type="text"
            placeholder="请输入手机号码"
            :disabled="status == 2"
            v-model="contact_info.mobile_phone"
          />
        </view>
        <view class="optionItem">
          <view class="optionTitle">
            <text>联系邮箱</text>
            <tip content="用于接收微信支付的开户邮件及日常业务通知"></tip>
          </view>
          <input
            type="text"
            placeholder="请输入联系邮箱"
            :disabled="status == 2"
            v-model="contact_info.contact_email"
          />
        </view>
      </view>
    </view>
    <view class="footer">
      <u-button
        @click="submit"
        :custom-style="{ width: '600rpx', height: '80rpx' }"
        type="error"
        shape="circle"
        :disabled="status == 2 || status == 4"
        >{{ status == 2 ? "审核中" : "立即提交" }}</u-button
      >
    </view>
  </view>
</template>

<script>
import myPicker from "./myPicker.vue";
import tip from "./tip.vue";
import showMore from "./showMore.vue";
import http from "@/common/http.js";
export default {
  props: {
    bind_store_id: {
      type: [String, Number],
      default: ""
    },
    status: {
      type: [String, Number],
      default: ""
    },
    info: {
      type: Object,
      default: () => {
        return {};
      }
    },
    mini_id: {
      type: [String, Number],
      default: ""
    }
  },
  data() {
    return {
      contact_info: {
        contact_name: "",
        contact_id_number: "",
        mobile_phone: "",
        contact_email: ""
      },
      subject_info: {
        // 主体类型 SUBJECT_TYPE_INDIVIDUAL 个体户 SUBJECT_TYPE_ENTERPRISE 企业 SUBJECT_TYPE_INSTITUTIONS 党政机关单位 SUBJECT_TYPE_OTHERS 其他组织
        subject_type: "",
        business_license_info: {
          license_copy: "",
          license_number: "",
          merchant_name: "",
          legal_person: ""
        },
        certificate_info: {
          is_long: 0,
          cert_copy: "",
          cert_type: "",
          cert_number: "",
          merchant_name: "",
          company_address: "",
          legal_person: "",
          period_begin: "",
          period_end: ""
        },
        organization_info: {
          is_composite: 0,
          organization_copy: "",
          organization_code: "",
          org_period_begin: "",
          org_period_end: "",
          is_long: 0
        },
        identity_info: {
          is_long: 0,
          id_doc_type: "",
          id_card_info: {
            id_card_copy: "",
            id_card_national: "",
            id_card_name: "",
            id_card_number: "",
            card_period_begin: "",
            card_period_end: ""
          },
          id_doc_info: {
            id_doc_copy: "",
            id_doc_name: "",
            id_doc_number: "",
            doc_period_begin: "",
            doc_period_end: ""
          }
        }
      },
      business_info: { merchant_shortname: "", service_phone: "" },
      bank_account_info: {
        bank_account_type: "",
        account_name: "",
        account_bank: "",
        bank_address_code: "",
        account_number: "",
        code_list: [],
        address_list: []
      },
      // 登记证书类型
      cert_type_list: [
        {
          name: "事业单位法人证书",
          value: "CERTIFICATE_TYPE_2388"
        },
        {
          name: "统一社会信用代码证书",
          value: "CERTIFICATE_TYPE_2389"
        },
        {
          name: "有偿服务许可证（军队医院适用）",
          value: "CERTIFICATE_TYPE_2390"
        },
        {
          name: "医疗机构执业许可证（军队医院适用）",
          value: "CERTIFICATE_TYPE_2391"
        },
        {
          name: "企业营业执照（挂靠企业的党组织适用）",
          value: "CERTIFICATE_TYPE_2392"
        },
        {
          name: "组织机构代码证（政府机关适用）",
          value: "CERTIFICATE_TYPE_2393"
        },
        {
          name: "社会团体法人登记证书",
          value: "CERTIFICATE_TYPE_2394"
        },
        {
          name: "民办非企业单位登记证书",
          value: "CERTIFICATE_TYPE_2395"
        },
        {
          name: "基金会法人登记证书",
          value: "CERTIFICATE_TYPE_2396"
        },
        {
          name: "慈善组织公开募捐资格证书",
          value: "CERTIFICATE_TYPE_2397"
        },
        {
          name: "农民专业合作社法人营业执照",
          value: "CERTIFICATE_TYPE_2398"
        },
        {
          name: "宗教活动场所登记证",
          value: "CERTIFICATE_TYPE_2399"
        },
        {
          name: "其他证书/批文/证明",
          value: "CERTIFICATE_TYPE_2400"
        }
      ],
      // 经营者/法人身份证件类型
      id_doc_list: [
        {
          name: "中国大陆居民-身份证",
          value: "IDENTIFICATION_TYPE_IDCARD"
        },
        {
          name: "其他国家或地区居民-护照",
          value: "IDENTIFICATION_TYPE_OVERSEA_PASSPORT"
        },
        {
          name: "中国香港居民-来往内地通行证",
          value: "IDENTIFICATION_TYPE_HONGKONG_PASSPORT"
        },
        {
          name: "中国澳门居民-来往内地通行证",
          value: "IDENTIFICATION_TYPE_MACAO_PASSPORT"
        },
        {
          name: "中国台湾居民-来往大陆通行证",
          value: "IDENTIFICATION_TYPE_TAIWAN_PASSPORT"
        }
      ],
      // 账户类型列表
      bank_type_list: [
        {
          name: "对公银行账户",
          value: "BANK_ACCOUNT_TYPE_CORPORATE"
        },
        {
          name: "经营者个人银行卡",
          value: "BANK_ACCOUNT_TYPE_PERSONAL"
        }
      ],
      // 银行列表
      bank_list: [
        "工商银行",
        "交通银行",
        "招商银行",
        "民生银行",
        "中信银行",
        "浦发银行",
        "兴业银行",
        "光大银行",
        "广发银行",
        "平安银行",
        "北京银行",
        "华夏银行",
        "农业银行",
        "建设银行",
        "邮政储蓄银行",
        "中国银行",
        "宁波银行"
      ],
      // 是否显示营业执照信息
      showBusiness: false,
      // 是否显示身份证信息
      showCard: false
    };
  },
  components: {
    myPicker,
    tip,
    showMore
  },
  methods: {
    // 点击选择图片
    addPic(e) {
      if (this.status == 2) return;

      this.$utils.uploadImage(1, (res) => {
        if (e == "license_copy") {
          this.subject_info.business_license_info.license_copy = res;
          this.analysis(res, 1, e);
        }
        if (e == "cert_copy") {
          this.subject_info.certificate_info.cert_copy = res;
        }
        if (e == "organization_copy") {
          this.subject_info.organization_info.organization_copy = res;
        }
        if (e == "id_card_copy") {
          this.subject_info.identity_info.id_card_info.id_card_copy = res;
          this.analysis(res, 2, e, "face");
        }
        if (e == "id_card_national") {
          this.subject_info.identity_info.id_card_info.id_card_national = res;
          this.analysis(res, 2, e, "back");
        }
        if (e == "id_doc_copy") {
          this.subject_info.identity_info.id_doc_info.id_doc_copy = res;
        }
      });
    },
    // 表单验证
    checkForm(type) {
      // 处于主体信息填写页面
      if (type == "subject_info" || type == "all") {
        if (
          this.subject_info.subject_type == "SUBJECT_TYPE_INDIVIDUAL" ||
          this.subject_info.subject_type == "SUBJECT_TYPE_ENTERPRISE"
        ) {
          if (this.subject_info.business_license_info.license_copy == "")
            return "请上传营业执照";
          if (this.subject_info.business_license_info.license_number == "")
            return "请填写注册号";
          if (this.subject_info.business_license_info.merchant_name == "")
            return "请填写商户名称";
          if (this.subject_info.business_license_info.legal_person == "")
            return "请填写经营者姓名";
        }
        if (
          this.subject_info.subject_type == "SUBJECT_TYPE_ENTERPRISE" ||
          this.subject_info.subject_type == "SUBJECT_TYPE_INSTITUTIONS" ||
          this.subject_info.subject_type == "SUBJECT_TYPE_OTHERS"
        ) {
          if (
            this.subject_info.subject_type == "SUBJECT_TYPE_INSTITUTIONS" ||
            this.subject_info.subject_type == "SUBJECT_TYPE_OTHERS"
          ) {
            if (this.subject_info.certificate_info.cert_copy == "")
              return "请上传登记证书照片";
            if (this.subject_info.certificate_info.cert_type == "")
              return "请选择登记证书类型";
            if (this.subject_info.certificate_info.cert_number == "")
              return "请填写证书号";
            if (this.subject_info.certificate_info.merchant_name == "")
              return "请填写商户名称";
            if (this.subject_info.certificate_info.company_address == "")
              return "请填写注册地址";
            if (this.subject_info.certificate_info.legal_person == "")
              return "请填写法人姓名";
            if (this.subject_info.certificate_info.period_begin == "")
              return "请选择登记证书有效开始日期";
            if (this.subject_info.certificate_info.is_long == 0) {
              if (this.subject_info.certificate_info.period_end == "")
                return "请选择登记证书有效结束日期";
            }
          }
          if (this.subject_info.organization_info.is_composite == 0) {
            if (this.subject_info.organization_info.organization_copy == "")
              return "请上传组织机构代码证照片";
            if (this.subject_info.organization_info.organization_code == "")
              return "请填写组织机构代码";
            if (this.subject_info.organization_info.org_period_begin == "")
              return "请选择组织机构代码证有效开始日期";
            if (this.subject_info.organization_info.is_long == 0) {
              if (this.subject_info.organization_info.org_period_end == "")
                return "请选择组织机构代码证有效结束日期";
            }
          }
        }
        if (
          this.subject_info.identity_info.id_doc_type ==
          "IDENTIFICATION_TYPE_IDCARD"
        ) {
          if (this.subject_info.identity_info.id_card_info.id_card_copy == "")
            return "请上传身份证人像面照片";
          if (
            this.subject_info.identity_info.id_card_info.id_card_national == ""
          )
            return "请上传身份证国徽面照片";
          if (this.subject_info.identity_info.id_card_info.id_card_name == "")
            return "请填写身份证姓名";
          if (this.subject_info.identity_info.id_card_info.id_card_number == "")
            return "请填写身份证号码";
          if (
            this.subject_info.identity_info.id_card_info.card_period_begin == ""
          )
            return "请选择身份证有效期开始时间";
          if (this.subject_info.identity_info.is_long == 0) {
            if (
              this.subject_info.identity_info.id_card_info.card_period_end == ""
            )
              return "请选择身份证有效期结束时间";
          }
        } else {
          if (this.subject_info.identity_info.id_doc_info.id_doc_copy == "")
            return "请上传证件照片";
          if (this.subject_info.identity_info.id_doc_info.id_doc_name == "")
            return "请填写证件姓名";
          if (this.subject_info.identity_info.id_doc_info.id_doc_number == "")
            return "请填写证件号码";
          if (
            this.subject_info.identity_info.id_doc_info.doc_period_begin == ""
          )
            return "请选择证件有效期开始时间";
          if (this.subject_info.identity_info.is_long == 0) {
            if (
              this.subject_info.identity_info.id_doc_info.doc_period_end == ""
            )
              return "请选择证件有效期结束时间";
          }
        }
      }
      // 处于经营信息填写页面
      if (type == "business_info" || type == "all") {
        if (this.business_info.merchant_shortname == "")
          return "请填写商户简称";
        if (this.business_info.service_phone == "") return "请填写客服电话";
      }
      // 处于结算账户填写页面
      if (type == "bank_account_info" || type == "all") {
        if (this.bank_account_info.bank_account_type == "")
          return "请选择账户类型";
        if (this.bank_account_info.account_name == "") return "请填写开户名称";
        if (this.bank_account_info.account_bank == "") return "请选择开户银行";
        if (this.bank_account_info.bank_address_code == "")
          return "请选择开户银行省市";
        if (this.bank_account_info.account_number == "")
          return "请填写银行账号";
      }
      // 处于超级管理员页面
      if (type == "contact_info" || type == "all") {
        if (this.contact_info.contact_name == "") return "请填写超级管理员姓名";
        if (this.contact_info.contact_id_number == "")
          return "请填写超级管理员身份证件号码";
        if (this.contact_info.mobile_phone == "")
          return "请填写超级管理员联系手机";
        if (this.contact_info.contact_email == "")
          return "请填写超级管理员联系邮箱";
      }
    },
    // 点击下一步或者提交按钮
    submit() {
      let type = "all";
      let flagText = this.checkForm(type);
      if (flagText && flagText != "") {
        uni.showToast({
          title: flagText,
          icon: "none"
        });
        return;
      }
      this.apply();
    },
    // 选择地区
    changeArea(e) {
      this.bank_account_info.code_list = e.detail.code;
      this.bank_account_info.address_list = e.detail.value;
      this.bank_account_info.bank_address_code = e.detail.code[2];
    },

    // 提交申请
    async apply() {
      if (this.status == 2 || this.status == 4) {
        return;
      }
      let param = {
        subject_info: this.subject_info,
        business_info: this.business_info,
        bank_account_info: this.bank_account_info,
        contact_info: this.contact_info
      };

      const res = await this.$allrequest.newStore.we_pay(
        {
          merchant_info: param,
          bind_store_id: this.bind_store_id,
          mini_id: this.mini_id
        },
        true
      );
      if (res.code == 0) {
        this.$utils.showModal("提示", "提交成功！", false, () => {
          uni.navigateBack({
            delta: 1
          });
        });
      }
    },
    // 解析图片
    async analysis(url, type, name, side) {
      const res = await this.$allrequest.merchant.analysis(
        { url, side, type },
        true
      );
      if (res.code == -1) {
        return;
      }
      if (res.code == 0) {
        if (name == "license_copy") {
          this.subject_info.business_license_info.license_number =
            res.data.reg_num;
          this.subject_info.business_license_info.merchant_name = res.data.name;
          this.subject_info.business_license_info.legal_person =
            res.data.person;
        }
        if (name == "id_card_copy") {
          this.subject_info.identity_info.id_card_info.id_card_name =
            res.data.name;
          this.subject_info.identity_info.id_card_info.id_card_number =
            res.data.num;
          this.contact_info.contact_id_number = res.data.num;
        }
        if (name == "id_card_national") {
          this.subject_info.identity_info.id_card_info.card_period_begin =
            res.data.start_date;
          this.subject_info.identity_info.id_card_info.card_period_end =
            res.data.end_date;
        }
      } else {
        if (name == "license_copy") {
          this.showBusiness = true;
        }
        if (name == "id_card_copy") {
          this.showCard = true;
        }
      }
    }
  },
  mounted() {
    if (this.info.contact_info) {
      this.contact_info = this.info.contact_info;
      this.subject_info = this.info.subject_info;
      this.business_info = this.info.business_info;
      this.bank_account_info = this.info.bank_account_info;
    }

    // if (this.status == 2 || this.status == 4) {
    // 	this.$emit('showTitle', 1)
    // }
    // if (this.status == 3) {
    // 	this.$emit('showTitle', 2)
    // }
  }
};
</script>

<style lang="scss" scoped>
.write {
  .payment {
    padding-left: 30rpx;
    padding-top: 20rpx;
    padding-bottom: 40rpx;
    font-family: PingFang SC;
    background-color: #fff;
    color: #262626;
    .title {
      display: flex;
      font-size: 24rpx;
      margin-top: 40rpx;
      color: #8c8c8c;
      padding-right: 30rpx;
      align-items: center;
      text:nth-child(1) {
        font-size: 26rpx;
        color: #262626;
        font-weight: 600;
      }
    }
    .optionItem {
      margin-top: 30rpx;
      display: flex;
      flex-direction: column;
      font-size: 24rpx;
      padding-right: 30rpx;
      .optionTitle {
        margin-bottom: 24rpx;
        display: flex;
        align-items: center;
      }
      .optionChoose {
        display: flex;
        align-items: center;
        justify-content: space-between;
        .iconfont {
          font-size: 24rpx;
          color: #888;
        }
      }
      .chooseType {
        display: flex;
        align-items: center;
        justify-content: space-between;
        color: #8c8c8c;
        font-size: 24rpx;
        .iconfont {
          font-size: 24rpx;
          color: #888;
        }
      }
      input {
        width: 100%;
      }
      .tip {
        font-size: 24rpx;
        color: #8c8c8c;
        margin-top: 24rpx;
        display: flex;
        flex-direction: column;
      }
      .sceneList {
        display: flex;
        flex-wrap: wrap;
        text {
          height: 60rpx;
          line-height: 60rpx;
          padding: 0 24rpx;
          background-color: #f2f2f2;
          border-radius: 30rpx;
          font-size: 24rpx;
          color: #8c8c8c;
          margin-right: 24rpx;
          margin-bottom: 24rpx;
          font-weight: 600;
        }
        .current {
          border: 1px solid #f60313;
          background-color: #fbeceb;
          color: #f0250e;
        }
      }
      .addPic {
        width: 160rpx;
        height: 160rpx;
        border-radius: 10rpx;
        background-color: #f6f6f6;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        overflow: hidden;
        font-size: 24rpx;
        color: #8c8c8c;
        .iconfont {
          font-size: 56rpx;
          margin-bottom: 12rpx;
        }
        image {
          width: 100%;
          height: 100%;
        }
      }
    }
    .underline {
      border-bottom: 1px solid #f8f8f8;
      padding-bottom: 24rpx;
    }
  }
  .footer {
    display: flex;
    padding-top: 10rpx;
    justify-content: center;
    border-top: 1px solid #f8f8f8;
    padding-bottom: 10rpx;
    padding-bottom: calc(constant(safe-area-inset-bottom) + 10rpx);
    padding-bottom: calc(env(safe-area-inset-bottom) + 10rpx);
    .btn {
      width: 80%;
      height: 80rpx;
      border-radius: 999px;
      background-color: #f0250e;
      color: #fff;
      font-size: 32rpx;
      font-weight: 600;
      display: flex;
      align-items: center;
      justify-content: center;
    }
  }
}
</style>
